//
//  SingleLineSelViewCell.m
//  Estate
//
//  Created by heyong on 16/6/22.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "SingleLineSelViewCell.h"
#import "NSString+Common.h"
#define kLabelMarginLeft    15
//#define kMarginTop          8
#define kLabelWidth         100
#define kGap    5

#define kInputLeftPos       120
#define kInputHeight        30
#define kInputMarginRight   40
#define kInputWidth         (kScreen_Width - kInputLeftPos - kInputMarginRight)

#define kTotalHeight    (kMarginTop*2 + kInputHeight)

@interface SingleLineSelViewCell()
@property (strong, nonatomic) UILabel *labelView;

@end

@implementation SingleLineSelViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        
        if (!_labelView) {
            _labelView = [[UILabel alloc] initWithFrame:CGRectMake(kLabelMarginLeft, kMarginTop, kLabelWidth, kInputHeight)];
            _labelView.font = [UIFont systemFontOfSize:kNormalFontSize];
            _labelView.textAlignment = NSTextAlignmentLeft;
            _labelView.textColor = UIColorFromRGB(0x797979);
            
            [self.contentView addSubview:_labelView];
        }
        
        if(!_labelSel){
            _labelSel = [[UILabel alloc] initWithFrame:CGRectMake(kInputLeftPos,kMarginTop,kInputWidth,kInputHeight)];
            _labelSel.font = [UIFont systemFontOfSize:kNormalFontSize];
            _labelSel.textAlignment = NSTextAlignmentLeft;
            _labelSel.numberOfLines = 0;
            _labelSel.textColor = [UIColor colorWithWhite:0.7 alpha:1];//kMenuNormalColor;
            
            [self addSubview:_labelSel];
        }
    }
    return self;
}

//- (void)awakeFromNib {
//    // Initialization code
//}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
}

- (void)setTttleSle:(NSString *)valueStr andLabel:(NSString *)label{
    _labelSel.text = valueStr;
    _labelView.text = label;
    
    CGFloat height = [valueStr boundingRectWithSize:CGSizeMake(kInputWidth, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:kNormalFontSize] forKey:NSFontAttributeName] context:nil].size.height;
    if (height < kInputHeight) {
        height = kInputHeight;
    }
    _labelSel.frame = CGRectMake(kInputLeftPos,kMarginTop,kInputWidth, height);
    
}

- (void)configDisplay:(NSString *)valueStr andLabel:(NSString*)label {
    _labelSel.text = valueStr;
    
    _labelView.text = label;
    
}
- (void)setColor:(UIColor *)color{
    _labelView.textColor = color;
    
}

- (void)configDisplay:(NSString *)valueStr andLabel:(NSString*)label color:(UIColor*)color
{
    _labelSel.text = valueStr;
    _labelView.text = label;
    _labelSel.textColor = color;
}


+ (CGFloat)cellHeight{
    return kTotalHeight;
}

+ (CGFloat)cellHeightWithObj:(id)obj{
    CGFloat cellHeight = 0;
    if ([obj isKindOfClass:[NSString class]]) {
        NSString *objStr = (NSString *)obj;
        cellHeight = [objStr getHeightWithFont:[UIFont systemFontOfSize:kNormalFontSize] constrainedToSize:CGSizeMake(kInputWidth, CGFLOAT_MAX)];
        if(cellHeight < kInputHeight){
            cellHeight = kInputHeight;
        }
        cellHeight += (kMarginTop * 2);
    }
    return cellHeight;
}

@end
